From b98aa152b340b2e77a25c92c413d5950af5f4ca8 Mon Sep 17 00:00:00 2001 From: Yuriy Shnitkovskiy Date: Mon, 2 Jan 2017 01:07:11 +0200 Subject: [PATCH] Avoid passing $this by reference in hooks Renamed $this passed by reference usages in hooks inside includes directory Bug: T153505 Change-Id: Ib3e6a288a423958e75b5c1bfe53dc29e0f3fee6d --- includes/Block.php | 4 +++- includes/OutputPage.php | 16 ++++++++++++---- includes/Revision.php | 4 +++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/includes/Block.php b/includes/Block.php index 20cb6145cc..9d3a2f935c 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -765,8 +765,10 @@ class Block { return false; } + // Avoid PHP 7.1 warning of passing $this by reference + $block = $this; # Allow hooks to cancel the autoblock. - if ( !Hooks::run( 'AbortAutoblock', [ $autoblockIP, &$this ] ) ) { + if ( !Hooks::run( 'AbortAutoblock', [ $autoblockIP, &$block ] ) ) { wfDebug( "Autoblock aborted by hook.\n" ); return false; } diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 9bae882d99..f140f548b3 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -1266,10 +1266,12 @@ class OutputPage extends ContextSource { } } + // Avoid PHP 7.1 warning of passing $this by reference + $outputPage = $this; # Add the remaining categories to the skin if ( Hooks::run( 'OutputPageMakeCategoryLinks', - [ &$this, $categories, &$this->mCategoryLinks ] ) + [ &$outputPage, $categories, &$this->mCategoryLinks ] ) ) { $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer(); foreach ( $categories as $category => $type ) { @@ -1810,8 +1812,10 @@ class OutputPage extends ContextSource { // Link flags are ignored for now, but may in the future be // used to mark individual language links. $linkFlags = []; + // Avoid PHP 7.1 warning of passing $this by reference + $outputPage = $this; Hooks::run( 'LanguageLinks', [ $this->getTitle(), &$this->mLanguageLinks, &$linkFlags ] ); - Hooks::run( 'OutputPageParserOutput', [ &$this, $parserOutput ] ); + Hooks::run( 'OutputPageParserOutput', [ &$outputPage, $parserOutput ] ); } /** @@ -1839,7 +1843,9 @@ class OutputPage extends ContextSource { */ public function addParserOutputText( $parserOutput ) { $text = $parserOutput->getText(); - Hooks::run( 'OutputPageBeforeHTML', [ &$this, &$text ] ); + // Avoid PHP 7.1 warning of passing $this by reference + $outputPage = $this; + Hooks::run( 'OutputPageBeforeHTML', [ &$outputPage, &$text ] ); $this->addHTML( $text ); } @@ -2358,9 +2364,11 @@ class OutputPage extends ContextSource { } MWDebug::addModules( $this ); + // Avoid PHP 7.1 warning of passing $this by reference + $outputPage = $this; // Hook that allows last minute changes to the output page, e.g. // adding of CSS or Javascript by extensions. - Hooks::run( 'BeforePageDisplay', [ &$this, &$sk ] ); + Hooks::run( 'BeforePageDisplay', [ &$outputPage, &$sk ] ); try { $sk->outputPage(); diff --git a/includes/Revision.php b/includes/Revision.php index aea8488983..8721ef9a56 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -1505,7 +1505,9 @@ class Revision implements IDBAccessObject { ); } - Hooks::run( 'RevisionInsertComplete', [ &$this, $data, $flags ] ); + // Avoid PHP 7.1 warning of passing $this by reference + $revision = $this; + Hooks::run( 'RevisionInsertComplete', [ &$revision, $data, $flags ] ); return $this->mId; } -- 2.20.1